/**
 * add by 维普  ，将编译后的代码增加的部分进行补充 2017-01-13（ningxuge）
*/
package ext.generic.erp.task;

import com.infoengine.SAK.Task;
import com.infoengine.util.IEException;
import ext.generic.erp.config.ERPPropertiesUtil;
import ext.generic.erp.util.IntegrationConstant;
import ext.generic.erp.util.PDMIntegrationLogUtil;
import java.io.IOException;
import java.util.Map;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;

public class AlternativeMaterialDeleteByChild
{
  private static String clazz = AlternativeMaterialDeleteByChild.class.getName();

  private static boolean verbose = PDMIntegrationLogUtil.verbose;

  private static String ieXMLFileDelete = null;

  static {
    ieXMLFileDelete = (String)ERPPropertiesUtil.getInstance().readProperties().get("replace_part_delete_ie_xml_file");

    initialCheck();
  }

  private static void initialCheck() {
    if (ieXMLFileDelete != null) {
      ieXMLFileDelete = ieXMLFileDelete.trim();

      PDMIntegrationLogUtil.printLog(clazz, "Delete Config File : " + ieXMLFileDelete, IntegrationConstant.LOG_LEVEL_NORMAL);
    } else {
      PDMIntegrationLogUtil.printLog(clazz, "Delete Config File : NULL" + ieXMLFileDelete, IntegrationConstant.LOG_LEVEL_ERROR);
    }
  }

  public static void delete(WTPartUsageLink wtUsageLink)
  {
    PDMIntegrationLogUtil.printLog(clazz, "Entering In delete( WTPartUsageLink wtUsageLink )......");

    if (wtUsageLink == null) {
      PDMIntegrationLogUtil.printLog(clazz, "delete Method, WTPartUsageLink is NULL", IntegrationConstant.LOG_LEVEL_WARN);
      return;
    }

    Task task = new Task(ieXMLFileDelete);

    IETaskCommonUtil.addWhereForDeleteByChild(wtUsageLink, task);
    try
    {
      PDMIntegrationLogUtil.printLog(clazz, "执行替代关系信息删除操作");
      task.invoke();
      PDMIntegrationLogUtil.printLog(clazz, "删除替代关系信息任务结束");
    } catch (IEException e) {
      PDMIntegrationLogUtil.printLog(clazz, "Throws IEException", IntegrationConstant.LOG_LEVEL_ERROR);
      PDMIntegrationLogUtil.printLog(clazz, e.toString(), IntegrationConstant.LOG_LEVEL_ERROR);

      e.printStackTrace();
    } catch (IOException e) {
      PDMIntegrationLogUtil.printLog(clazz, "Throws IOException", IntegrationConstant.LOG_LEVEL_ERROR);
      PDMIntegrationLogUtil.printLog(clazz, e.getMessage(), IntegrationConstant.LOG_LEVEL_ERROR);

      e.printStackTrace();
    } finally {
      PDMIntegrationLogUtil.printLog(clazz, "Existed Out delete( WTPartUsageLink wtUsageLink )......");
    }
  }

  public static void delete(WTPartMaster master)
  {
    PDMIntegrationLogUtil.printLog(clazz, "Entering In delete( WTPartMaster master )......");

    if (master == null) {
      PDMIntegrationLogUtil.printLog(clazz, "delete Method, WTPartMaster is NULL", IntegrationConstant.LOG_LEVEL_WARN);
      return;
    }

    Task task = new Task(ieXMLFileDelete);

    IETaskCommonUtil.addWhereForDeleteByChild(master, task);
    try
    {
      PDMIntegrationLogUtil.printLog(clazz, "执行替代关系信息删除操作");
      task.invoke();
      PDMIntegrationLogUtil.printLog(clazz, "删除替代关系信息任务结束");
    } catch (IEException e) {
      PDMIntegrationLogUtil.printLog(clazz, "Throws IEException", IntegrationConstant.LOG_LEVEL_ERROR);
      PDMIntegrationLogUtil.printLog(clazz, e.toString(), IntegrationConstant.LOG_LEVEL_ERROR);

      e.printStackTrace();
    } catch (IOException e) {
      PDMIntegrationLogUtil.printLog(clazz, "Throws IOException", IntegrationConstant.LOG_LEVEL_ERROR);
      PDMIntegrationLogUtil.printLog(clazz, e.getMessage(), IntegrationConstant.LOG_LEVEL_ERROR);

      e.printStackTrace();
    } finally {
      PDMIntegrationLogUtil.printLog(clazz, "Existed Out delete( WTPartMaster master )......");
    }
  }
}